package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.sugon.dao.ErmsTodoListDao;
import com.sugon.entity.ErmsTodoList;
import com.sugon.service.ErmsTodoListService;
import com.sugon.service.SysDeptService;
import com.sugon.utils.Constant;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 异常跟踪记录Service实现类
 *
 * @author sugon
 * @date 2019-08-08 20:21:51
 */
@Service("todoListService")
public class ErmsTodoListServiceImpl implements ErmsTodoListService {
    @Autowired
    private ErmsTodoListDao todoListDao;
    @Autowired
    private SysDeptService sysDeptService;

    @Override
    public ErmsTodoList queryObject(String id) {
        return todoListDao.queryObject(id);
    }

    @Override
    public List<ErmsTodoList> queryList(Map<String, Object> map) {
        return todoListDao.queryList(map);
    }

    @Override
    public List<ErmsTodoList> queryListApi(Map<String, Object> map, String inspectionRecords, Integer leader, String deptId) {
        //判断当前是否是工单执行人
        /*Integer  leader =ShiroUtils.getUserEntity().getLeader();*/
        //根据当前用户部门id 查询所属科室
        String type = sysDeptService.getDeptTypeById(deptId);
        if (1 == leader) {

        } else {
            if ("DT_SBWXZ".equals(type)) {
                //map.put("createUser",ShiroUtils.getUserId());
//               map.put("status",1);
            } else {
                map.put("status", 1);
            }
        }
        return todoListDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return todoListDao.queryTotal(map);
    }

    @Override
    public int saveApi(ErmsTodoList excepRecord) {
        excepRecord.setId(RandomUtil.randomString(32));
//        excepRecord.setCreateDate(new Date());
//        excepRecord.setIsCheck(0);
        excepRecord.setDelFlag(1);
//        excepRecord.setIsRepair(0);
        return todoListDao.save(excepRecord);
    }

    @Override
    public int save(ErmsTodoList excepRecord) {
        excepRecord.setId(RandomUtil.randomString(32));
        excepRecord.setDelFlag(Constant.IS_NOT_DEL_INT);
        excepRecord.setCreateTime(DateUtil.date());
        if (StrUtil.isEmpty(excepRecord.getCreateBy())) {
            excepRecord.setCreateBy(ShiroUtils.getUserId());
        }
        return todoListDao.save(excepRecord);
    }

    @Override
    public int update(ErmsTodoList excepRecord) {
        return todoListDao.update(excepRecord);
    }

    @Override
    public int delete(String id) {
        return todoListDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return todoListDao.deleteBatch(ids);
    }

}

